<template>
	<view class="body">
		<view class="list">
			<view class="list-item" v-for="item in list" :key="item.id" >
				<view class="center" @tap="chooseArea(item)">
					<view class="name">{{item.name}}</view>
					<view class="tel">{{item.phoneNumber}}</view>
				</view>
				<view class="right">
					<navigator :url="`./editAddress/editAddress?addressId=${item.id}`">
						<image class="icon" src="../../static/icons/edit.png"></image>
					</navigator>
				</view>
			</view>
		</view>
		<navigator url="./addAddress/addAddress">
		<view class="add">
			<view class="btn">新增地址</view>
		</view>
		</navigator>
	</view>
</template>

<script>
	import {findAllAddress} from "../../api/address/index.js"
	import mix from "../../mixins/index.js"
	export default {
		mixins:[mix],
		data() {
			return {
				list:[]
			};
		},
		onLoad() {
			if(!this.checkLogins()){
				return
			}
			findAllAddress().then(res=>{
				console.log(res)
				this.list = res.data.items
			})
		},
		methods:{
			chooseArea(val){
				uni.setStorageSync("chooseArea",val);
				uni.navigateBack({
					delta:1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.body{
		height: 100vh;
		background-color: #F1ECE7;
		.list{
			display: flex;
			flex-wrap: wrap;
			.list-item{
				width: 94%;
				padding: 10px 0;
				margin: 0 auto;
				border-bottom: 1px solid #ccc;
				display: flex;
				justify-content: space-between;
				align-items: center;
				.center{
					width: 85%;
					.name{
						margin-left: 15px;
						margin-bottom: 10px;
					}
					.tel{
						margin-left: 15px;
						font-size: 12px;
						color: #999;
					}
				}
				.right{
					display: flex;
					justify-content: center;
					align-items: center;
					width: 40px;
					height: 30px;
					border-left: 1px solid #aaa;
					color: #777;
					.icon{
						width: 20px;
						height: 20px;
					}
				}
			}
		}
		.add{
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			height: 60px;
			display: flex;
			justify-content: center;
			align-items: center;
			.btn{
				width: 70%;
				height: 40px;
				line-height: 40px;
				text-align: center;
				border-radius: 40px;
				font-size: 15px;
				background-color: #354e44;
				color: #fff;
			}
		}
	}
</style>
